﻿using System;

class BitValueAtPositionB
{
    static void Main()
    {
        Console.WriteLine("Enter an integer number:");
        int number = Int32.Parse(Console.ReadLine());
        Console.WriteLine("Enter bit position (from 0 to 31):");
        int bitPosition = Int32.Parse(Console.ReadLine());
        int mask;
        int nAndMask;
        int bitValue;
        if (bitPosition >= 0 && bitPosition <= 31)
        {
            mask = 1 << bitPosition;
            nAndMask = number & mask;
            bitValue = nAndMask >> bitPosition;
            Console.WriteLine("Number [{0}], bit position [{1}], bit value [{2}].", number, bitPosition, bitValue);
        }
        else
        {
            Console.WriteLine("Invalid bit position.");
        }
    }
}
